package com.cdx.spring.jdkproxy;

import com.cdx.spring.proxy.HHUser;
import com.cdx.spring.proxy.UserService;
import com.cdx.spring.proxy.UserServiceImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author chedx
 * @data 2021/1/11 10:46 PM
 */
public class TestJDKProxy {
    public static void main(String[] args) {
        final UserService userService = new UserServiceImpl();

        InvocationHandler handler = new InvocationHandler(){
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("------proxy  log");
                Object ret = method.invoke(userService, args);
                return ret;
            }
        };

        UserService userServiceProxy = (UserService) Proxy.newProxyInstance(TestJDKProxy.class.getClassLoader(),userService.getClass().getInterfaces(),handler);

        userServiceProxy.login(new HHUser());




    }
}
